import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:yysk_app/pages/main/main_controller.dart';
import 'package:yysk_app/pages/nft_pages/pay_pages/confirm_payment/confirm_payment_controller.dart';
import 'package:yysk_app/routes/global_controller.dart';
import 'package:yysk_app/utils/colors.dart';
import 'package:yysk_app/utils/helper.dart';
import 'package:yysk_app/utils/js_tool.dart';
import 'package:yysk_app/widget/button_widget.dart';
import 'package:yysk_app/widget/image_asset_widget.dart';
import 'package:yysk_app/widget/input_widget.dart';
import 'package:yysk_app/widget/lazy_network_image.dart';
import 'package:oktoast/oktoast.dart';

//支付code弹窗
Future<void> showBankPayCodeSheet() async {
  // final GlobalController globalController = Get.find();
  final ConfirmPaymentController controller = Get.find();
  controller.codeController.clear();
  controller.payCode.value = '';
  controller.smsBtnText.value = '获取验证码';
  showModalBottomSheet(
    context: Get.context!,
    isDismissible: false,
    isScrollControlled: true,

    backgroundColor: Color.fromRGBO(0, 0, 0, 0),
    builder: (BuildContext context) {
      return BottomSheet(
        onClosing: () {},
        enableDrag: false, // 禁止拖拽，否则报错
        backgroundColor: Color.fromRGBO(0, 0, 0, 0),
        builder: (BuildContext context) {
          return Container(
            padding: EdgeInsets.fromLTRB(
              0,
              0,
              0,
              MediaQuery.of(context).viewInsets.bottom,
            ),

            // height: MediaQuery.of(context).size.height,
            height:
                306.px +
                (controller.isFocused.value
                    ? MediaQuery.of(context).viewInsets.bottom
                    : 0),
            constraints: BoxConstraints(minHeight: 306.px),
            width: MediaQuery.of(context).size.width,

            // clipBehavior: Clip.antiAlias,
            child: Stack(
              children: [
                Column(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                  
                    Expanded(
                      child: Container(
                        clipBehavior: Clip.antiAlias,
                        decoration: BoxDecoration(
                          color: AppColors.backgroundColorGreyF7,

                          borderRadius: BorderRadius.only(
                            topLeft: Radius.circular(20.px),
                            topRight: Radius.circular(20.px),
                          ),
                        ),
                        child: ListView(
                          children: [
                          
                            SizedBox(height: 21.px),
                            Text(
                              '请填写支付验证码',
                              style: TextStyle(
                                color: AppColors.fontColorBlack,
                                fontSize: 16.px,
                                fontWeight: FontWeight.w500,
                              ),
                              textAlign: TextAlign.center,
                            ),
                            SizedBox(height: 40.px),
                            Text(
                              '发送手机号：${controller.mobile.value}',
                              style: TextStyle(
                                color: Color.fromRGBO(34, 34, 34, 1),
                                fontSize: 18.px,
                                fontWeight: FontWeight.w400,
                                fontFamily: 'CustomPINGFANG'
                              ),
                              textAlign: TextAlign.center,
                            ),
                            SizedBox(height: 27.px),
                            Obx(()=>    Center(
                              child: SizedBox(
                                width: 329.px,
                                // height: 78.px,
                                child: Stack(
                                  children: [
                                        InputWidget(
                                  focusNode: controller.focusNode,
                                  maxLength: 6,
                                  controller: controller.codeController,
                                  inputType: TextInputType.text,
                                  height: 50.px,
                                  hint: '输入验证码',
                                  backgroundColor: AppColors.backgroundColor,
                                  onChanged: (value) {
                                    controller.payCode.value = value;
                                  },
                                ),
                                    Positioned(
                                      right: 0,
                                      top: 0,
                                      child: Container(
                                      width: 100.px,
                                      height: 50.px,
                                      color: Color.fromRGBO(1, 1, 1, 0),
                                      child:GestureDetector(
                                        onTap: (){
                                          if(controller.smsBtnText.value=='获取验证码'){
                                          controller.getbankCardId();
                                          }
                                        },
                                        child:  Center(
                                        child: 
                                        Text('${controller.smsBtnText}',style: TextStyle(fontSize: 14.px,color: AppColors.backgroundColorBlack,fontFamily: 'CustomPINGFANG'),)
                                      ),
                                      ),
                                    ))
                                  ],
                                )
                             ),
                            ),
                        )
                          ],
                        ),
                      ),
                    ),
                    Container(
                      color: AppColors.backgroundColorGreyF7,
                      height: 82.px,
                      child: Center(
                        child: ButtonWidget(
                          label: '确认支付',
                          width: 322.px,
                          height: 54.px,
                          imageBg: 'static/images/btm.png',
                          contentType: ContentType.other,
                          fontSize: 16.px,
                          fontColor: AppColors.backgroundColorLightGreen,
                          onPressed: () {
                            if (controller.codeController.text == '') {
                              showToast('请输入验证码');
                              return;
                            }
                            controller.pay();
                          },
                        ),
                      ),
                    ),
                  ],
                ),
                Positioned(
                  right: 25.px,
                  top: 25.px,
                  child:GestureDetector(
                    onTap: (){
                        Navigator.of(context).pop();
                    },
                    child:  ImageAssetWidget(imageUrl: 'static/images/wallet/pay_close.png',width: 22.px,height: 22.px,),
                  ))
              ],
            ),
          );
        },
      );
    },
  );
}
